package jmine.tec.database.query;

import java.util.ArrayList;
import java.util.List;

import jmine.tec.test.Builder;

/**
 * Builder de ExportedKey
 * 
 * @author lundberg
 */
public class ExportedKeyBuilder implements Builder<ExportedKey> {

    private Database database;

    private String referenced;

    private String referencing;

    private List<String> referencedColumns = new ArrayList<String>();;

    private List<String> referencingColumns = new ArrayList<String>();;

    public static ExportedKeyBuilder anExportedKey() {
        return new ExportedKeyBuilder();
    }

    public ExportedKey build() {
        ExportedKey exported = new ExportedKey(this.database.findTable(this.referenced), this.database.findTable(this.referencing));
        for (int i = 0; i < this.referencedColumns.size(); i++) {
            exported.addReference(this.referencedColumns.get(i), this.referencingColumns.get(i));
        }
        return exported;
    }

    /**
     * @param database the database to set
     */
    public ExportedKeyBuilder on(Database database) {
        this.database = database;
        return this;
    }

    /**
     * @param referenced the referenced to set
     */
    public ExportedKeyBuilder to(String referenced) {
        this.referenced = referenced;
        return this;
    }

    /**
     * @param referencing the referencing to set
     */
    public ExportedKeyBuilder from(String referencing) {
        this.referencing = referencing;
        return this;
    }

    /**
     * @param referencedColumns the referencedColumns to set
     */
    public ExportedKeyBuilder relating(String referencingColumn, String referencedColumn) {
        this.referencingColumns.add(referencingColumn);
        this.referencedColumns.add(referencedColumn);
        return this;
    }
}
